<script setup>
import { onMounted, ref } from 'vue'
import { getLogListService } from '@/api/log/log'

const logList = ref([])
const page = ref(1)
const pageSize = ref(10)
const total = ref(0)
const queryParams = ref({
  page: 1,
  pageSize: 9,
  name: null
})
const getLogList = async () => {
  const res = await getLogListService(queryParams.value)
  logList.value = res.data.data.records
  total.value = res.data.data.total
}

const handleQuery = () => {
  queryParams.value.page = 1
  getLogList()
}
const resetForm = () => {
  queryParams.value.name = null
  handleQuery()
}
//在页面初次渲染执行
onMounted(() => {
  getLogList()
})
</script>

<template>
  <div class="floating-box">
    <div>
      <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        label-width="68px"
        class="no-wrap"
        @keydown.enter.prevent
      >
        <el-form-item label="用户" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入用户姓名"
            prefix-icon="Search"
            style="width: 250px"
            @keyup.enter="handleQuery()"
          />
        </el-form-item>
        <el-form-item>
          <div class="no-wrap">
            <el-button
              icon="Search"
              plain
              round
              color="#95d475"
              @click="handleQuery()"
              >搜索</el-button
            >
            <el-button
              icon="Refresh"
              plain
              round
              color="#95d475"
              @click="resetForm()"
              >重置</el-button
            >
          </div>
        </el-form-item>
      </el-form>
      <el-divider />
    </div>
    <el-table :data="logList" width="100%" :stripe="true" size="large">
      <el-table-column
        label="用户"
        prop="userName"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="描述"
        prop="description"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="浏览器标识"
        prop="browserInfo"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="IP地址"
        prop="ipAddress"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="时间"
        prop="time"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        v-model:current-page="queryParams.page"
        v-model:page-size="queryParams.pageSize"
        layout="total, prev, pager, next, jumper"
        v-show="total > 0"
        :total="total"
        @size-change="getLogList"
        @current-change="getLogList"
      />
    </div>
  </div>
</template>

<style scoped>
/* 设置每个单元格的内边距 */
/deep/ .el-table .el-table__body-wrapper tbody td {
  padding: 14px 0 14px 0; /* 设置每个单元格的上下左右内边距为 5px，你可以根据需要调整 */
}

/deep/ .el-input__wrapper {
  border-radius: 50px;
  /*background-color: red;*/
}
</style>
